package com.example.multity

import android.annotation.SuppressLint
import android.app.ComponentCaller
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.Bundle
import android.provider.MediaStore
import android.widget.Button
import android.widget.ImageView
import androidx.activity.ComponentActivity
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity


class forthActivity : ComponentActivity() {

    private lateinit var buttontakephoto: Button
    private lateinit var backbutton: Button
    private lateinit var imagephoto: ImageView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_forth)
        buttontakephoto = findViewById(R.id.Button_take_photo)
        imagephoto = findViewById(R.id.imageView_take_photo)
        backbutton=findViewById(R.id.button_fourth_back)
        buttontakephoto.setOnClickListener {
            dispatchTakePictureIntent()
        }
        backbutton.setOnClickListener {
            finish()
        }

    }


    val REQUEST_IMAGE_CAPTURE = 1
    @SuppressLint("QueryPermissionsNeeded")
    private fun dispatchTakePictureIntent() {
        val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        if (intent.resolveActivity(packageManager) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE)

        }
    }

    override fun onActivityResult(
        requestCode: Int,
        resultCode: Int,
        data: Intent?,
    ) {
        super.onActivityResult(requestCode, resultCode, data)
        if(requestCode==REQUEST_IMAGE_CAPTURE&&resultCode==RESULT_OK){
            val imageBitmap=data?.extras?.get("data")as Bitmap
            imagephoto.setImageBitmap(imageBitmap)
            }
    }
}




